"use strict";

angular.module('app.yksensor').controller('YKStoreDetailCtrl', function ($scope,$http,$cookieStore) {

    $scope.backtoStore = function(){
        window.location.href = appConfig.base[0].baseURI + "#/yk_store";
    }

    var _tank_id = $cookieStore.get('tank_id') == undefined ? 1 : $cookieStore.get('tank_id');
    console.log(_tank_id)
    $http.get('api/tank.json').success(function(res){
        for(var i=0; i<res.length; i++){
            if(res[i].id == _tank_id){
                $scope.tankInfo = res[i];
                console.log($scope.tankInfo)
            }
        }
    })

    //编辑温度计高度 和报警温度
    $scope.edit = function(tid){
        var high = $('.detail-right-table tr:eq('+tid+')').children('td:eq(1)').html();
        var alert = $('.detail-right-table tr:eq('+tid+')').children('td:eq(2)').html();

        $('.detail-right-table tr:eq('+tid+')').children('td:eq(1)').html('<input type="text" class="input-xs high-input" style="width:58px" value="'+high+'" />')
                            .next().html('<input type="text" class="input-xs alert-input" style="width:58px" value="'+alert+'" />')
                            .next().append('<button class="btn btn-success btn-ok" style="padding:1px 5px;"><i class="fa fa-check"></i></button>')


        $('.btn-ok').click(function(){
            console.log('ok')
            $(this).parents('tr').children('td:eq(1)').html($('.high-input').val())
                                .next().html($('.alert-input').val())
                                .next().children('.btn-ok').remove()
        })
    }

    $scope.tankcharts = function(tankid){
        window.location.href = appConfig.base[0].baseURI + '#/yk_tankcharts/'+ tankid;
    }
        
});

